home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 3006 / 3006.xpi / components / dhDownloadConvertProcessor.js < prev    next >
Text File  |  2010-01-15  |  6KB  |  170 lines

  1. /******************************************************************************
  2.  *            Copyright (c) 2006-2009 Michel Gutierrez. All Rights Reserved.
  3.  ******************************************************************************/
  4.  
  5. /**
  6.  * Constants.
  7.  */
  8.  
  9. const NS_DLCPROC_CID = Components.ID("{f9f662a6-77d4-437e-8f53-4fcc39fddf47}");
  10. const NS_DLCPROC_PROG_ID = "@downloadhelper.net/download-convert-processor;1";
  11. const DHNS = "http://downloadhelper.net/1.0#";
  12.  
  13. var Util=null;
  14.  
  15. /**
  16. * Object constructor
  17. */
  18. function DLCProc() {
  19.     try {
  20.         //dump("[DLCProc] constructor\n");
  21.         this.helper=new DLProcHelper();
  22.         this.core=Components.classes["@downloadhelper.net/core;1"].
  23.             getService(Components.interfaces.dhICore);
  24.         this.cvMgr=Components.classes["@downloadhelper.net/convert-manager-component"]
  25.                                           .getService(Components.interfaces.dhIConvertMgr);
  26.         this.core.registerProcessor(this);
  27.     } catch(e) {
  28.         dump("[DLCProc] !!! constructor: "+e+"\n");
  29.     }
  30. }
  31.  
  32. DLCProc.prototype = {
  33.     get name() { return "convert-choice"; },
  34.     get provider() { return "DownloadHelper"; },
  35.     get title() { return Util.getText("processor.convert-choice.title"); },
  36.     get description() { return Util.getText("processor.convert-choice.description"); },
  37.     get enabled() { return true; },
  38. }
  39.  
  40. DLCProc.prototype.canHandle=function(desc) {
  41.     //dump("[DLCProc] canHandle()\n");
  42.     if(!this.helper.canHandle(desc))
  43.         return false;
  44.     return true;
  45.     //return this.cvMgr.checkConverter(false);
  46. }
  47.  
  48. DLCProc.prototype.requireDownload=function(desc) {
  49.     //dump("[DLCProc] requireDownload()\n");
  50.     return this.helper.requireDownload(desc);
  51. }
  52.  
  53. DLCProc.prototype.preDownload=function(desc) {
  54.     //dump("[DLCProc] preDownload()\n");
  55.     return this.helper.preDownload(desc,true,true);
  56. }
  57.  
  58. DLCProc.prototype.handle=function(desc) {
  59.     //dump("[DLCProc] handle()\n");
  60.     this.helper.handle(desc,true);
  61. }
  62.  
  63. DLCProc.prototype.QueryInterface = function(iid) {
  64.     //dump("[DLCProc] QueryInterface("+iid+")\n");
  65.     if(
  66.         iid.equals(Components.interfaces.dhIProcessor) ||
  67.         iid.equals(Components.interfaces.nsISupports)
  68.     ) {
  69.         return this;
  70.     }
  71.     throw Components.results.NS_ERROR_NO_INTERFACE;
  72. }
  73.  
  74. var vDLCProcModule = {
  75.     firstTime: true,
  76.     
  77.     /*
  78.      * RegisterSelf is called at registration time (component installation
  79.      * or the only-until-release startup autoregistration) and is responsible
  80.      * for notifying the component manager of all components implemented in
  81.      * this module.  The fileSpec, location and type parameters are mostly
  82.      * opaque, and should be passed on to the registerComponent call
  83.      * unmolested.
  84.      */
  85.     registerSelf: function (compMgr, fileSpec, location, type) {
  86.  
  87.         if (this.firstTime) {
  88.             this.firstTime = false;
  89.             throw Components.results.NS_ERROR_FACTORY_REGISTER_AGAIN;
  90.         }
  91.         compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
  92.         compMgr.registerFactoryLocation(NS_DLCPROC_CID,
  93.                                         "DLCProc",
  94.                                         NS_DLCPROC_PROG_ID, 
  95.                                         fileSpec,
  96.                                         location,
  97.                                         type);
  98.     },
  99.  
  100.     unregisterSelf: function(compMgr, fileSpec, location) {
  101.         compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
  102.         compMgr.unregisterFactoryLocation(NS_DH_DLCPROC_CID, fileSpec);
  103.     },
  104.  
  105.     /*
  106.      * The GetClassObject method is responsible for producing Factory and
  107.      * SingletonFactory objects (the latter are specialized for services).
  108.      */
  109.     getClassObject: function (compMgr, cid, iid) {
  110.         if (!cid.equals(NS_DLCPROC_CID)) {
  111.             throw Components.results.NS_ERROR_NO_INTERFACE;
  112.         }
  113.  
  114.         if (!iid.equals(Components.interfaces.nsIFactory)) {
  115.             throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
  116.         }
  117.  
  118.         return this.vDLCProcFactory;
  119.     },
  120.  
  121.     /* factory object */
  122.     vDLCProcFactory: {
  123.         /*
  124.          * Construct an instance of the interface specified by iid, possibly
  125.          * aggregating it with the provided outer.  (If you don't know what
  126.          * aggregation is all about, you don't need to.  It reduces even the
  127.          * mightiest of XPCOM warriors to snivelling cowards.)
  128.          */
  129.         createInstance: function (outer, iid) {
  130.             if (outer != null) {
  131.                 throw Components.results.NS_ERROR_NO_AGGREGATION;
  132.             }
  133.     
  134.             if(Util==null) {
  135.                 Util=Components.classes["@downloadhelper.net/util-service;1"]
  136.                     .getService(Components.interfaces.dhIUtilService);
  137.                 try {
  138.                     var jsLoader=Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
  139.                         .getService(Components.interfaces.mozIJSSubScriptLoader);
  140.                     jsLoader.loadSubScript("chrome://dwhelper/content/dlproc-helper.js");
  141.                 } catch(e) {
  142.                     dump("!!! [dhDownloadProcessor] createInstance: "+e+"\n");
  143.                 }
  144.             }
  145.  
  146.             return new DLCProc().QueryInterface(iid);
  147.         }
  148.     },
  149.  
  150.     /*
  151.      * The canUnload method signals that the component is about to be unloaded.
  152.      * C++ components can return false to indicate that they don't wish to be
  153.      * unloaded, but the return value from JS components' canUnload is ignored:
  154.      * mark-and-sweep will keep everything around until it's no longer in use,
  155.      * making unconditional ``unload'' safe.
  156.      *
  157.      * You still need to provide a (likely useless) canUnload method, though:
  158.      * it's part of the nsIModule interface contract, and the JS loader _will_
  159.      * call it.
  160.      */
  161.     canUnload: function(compMgr) {
  162.         return true;
  163.     }
  164. };
  165.  
  166. function NSGetModule(compMgr, fileSpec) {
  167.     return vDLCProcModule;
  168. }
  169.  
  170.